package com.pastquestion;

import java.io.IOException;
import java.util.Scanner;

public class Main10a {
	public static void main(String[] args) throws IOException {
		int[][] a = new int[20][5];
//		BufferedReader bf = new BufferedReader(new InputStreamReader(new FileInputStream("C:\\Users\\shuoye\\Desktop\\bf.txt")));
		Scanner bf = new Scanner(System.in);
		int len = 20;
		for (int i = 0; i < len; i++) {
			for (int j = 0; j < a[i].length; j++) {
				a[i][j] = bf.nextInt();
			}
		}
		
		int max = 0;
		for (int i = 0; i < a.length; i++) {
			for (int j = 0;j < a.length; j++) {
				if(i == j)
					continue;
				for (int j2 = 0; j2 < a.length; j2++) {
					if(i == j2 ||  j2 == j )
						continue;
					for (int k = 0; k < a.length; k++) {
						if(i == k ||  k == j2 || k == j )
							continue;
						for (int k2 = 0; k2 < a.length; k2++) {
							if(i == k2 ||  k2 == j2 || k2 == j || k2 == k)
								continue;
							max = Math.max(max, a[i][0] + a[j][1] + a[j2][2] + a[k][3] + a[k2][4]);
						}
					}
				}
			}
		}
		System.out.println(max);
	}
	
}
